<script type="text/plain" id="upload_ue" style="height:5px;display:none;" ></script>
<script type="text/javascript" src="/static/ueditor/third-party/jquery-1.10.2.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script>
    //实例化编辑器
    const _editor = UE.getEditor('upload_ue');
    const host = localStorage.getItem('host');
    _editor.ready(function () {
        //设置编辑器不可用
        //ue_editor.setDisabled();
        //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
        _editor.hide();

        //监听图片上传
        _editor.addListener('beforeInsertImage', function (t,arg)
        {
            //将地址赋值给相应的input
            $("#picture").attr("value", host + arg[0].src);
            //图片预览
            $("#preview").attr("src", host + arg[0].src);
        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * me.execCommand('insertHtml', html);
         * me.fireEvent('afterUpFile', filelist);//wmainng
         */
        _editor.addListener('afterUpFile', function (t, arg)
        {
            $("#file").attr("value", host + arg[0].url);
        });
    });

    //弹出图片上传的对话框
    function upImage()
    {
        const myImage = _editor.getDialog("insertimage");
        myImage.open();
    }

    //弹出文件上传的对话框
    function upFile()
    {
        const myFiles = _editor.getDialog("attachment");
        myFiles.open();
    }
</script>